var util = require('../../utils/util.js');
var utilMd5 = require('../../utils/md5.js');
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    classlyType: 0,
    classlysData:'',
    token: "",
    uid: 0,
    show_edit_view: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.setNavigationBarTitle({
      title: options.title,
    });

    app.LoginUserInfo(function (res) {
      if (res && res != -1) {
        that.setData({
          uid: res.uid,
          token: res.token,
          classlyType: options.type
        });

        that.loadClasslyData(options.type);
      }
    });
  },

  loadClasslyData: function (getType) {
    var that = this;
    var uid = this.data.uid;
    var params = '';
    var actionItem = '';
    if (getType == 9) {
      params = {
        ac: "getalbum",
        publickey: util.publiccode,
        uid: uid,
        type: 3
      }
      var actionItem = {
        name: "新增分类",
        add: 1
      }
    }
    
    util.api({
      data: params,
      success: function (responseData) {
        var result = responseData.data;
        console.log("文字类别：", result);
        if (result.res && result.msg) {

        } else {
          if(actionItem) {
            result = result.concat(actionItem);
          }
          that.setData({
            classlysData: result
          });
        }

      }
    });
  },

  selAction: function (e) {
    console.log("selAction:", e.currentTarget.dataset.item);
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2]; //上一个页面
    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    prevPage.setData({
      selClassly: e.currentTarget.dataset.item
    })
    wx.navigateBack();
  }, 

  addAction:function(e){
    console.log("addAction");
    this.setData({
      show_edit_view: true
    });
  },  

  delAction: function (e) {
    console.log("delAction");
  },  

  editAction: function (e) {
    console.log("editAction");
    this.setData({
      show_edit_view: true
    });
  }, 

  hiddenEditView:function(){
    this.setData({
      show_edit_view: false
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})